package com.qianniu.napi.admin.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 优惠券模板
 * </p>
 *
 * @author chenxuebin
 * @since 2018-07-07
 */
@TableName("t_coupon_tpl")
public class CouponTpl extends Model<CouponTpl> implements Comparable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 优惠券模板名称
     */
    private String name;
    private String xmtype;
    /**
     * 商家名称
     */
    private String sname;
    private String address;
    private String pic;
    /**
     * 优惠券类型@1：代金券；2：满减券；3：折扣券；4：兑换券；5：积分；6：配送券；10:次卡；11：周卡；12：月卡；13：季卡；14：半年卡；15：年卡；16：畅游卡；&
     */
    private Integer type;

    //分享转增模式@1：分享领取；2：赠送领取
    private Integer zsmode;
    /**
     * 优惠券类型中文名称@1:代金券；2：满减券；3:折扣券;4:体验金；5：加息券
     */
    @TableField(exist = false)
    private String typeName;

    /**
     * 能否重复用领
     */
    @TableField("is_repeat")
    private Integer isRepeat;
    private Integer fenxiao;

    private Integer state;
    /**
     * 可重复领取张数
     */
    @TableField("repeat_num")
    private Integer repeatNum;
    /**
     * 发放总数量
     */
    private Integer total;
    private Integer expire;

    private Integer ismember;
    private Integer mlevel;

    private Integer use=0;
    private Integer used;

    @TableField(exist = false)
    private Long cid;

    /**
     * 总价值
     */
    private BigDecimal discount;
    /**
     * 生效方式@1：领取生效；2：固定日期开始生效
     */
    @TableField("valid_type")
    private Integer validType;

    @TableField("is_forever")
    private Integer isForever;

    @TableField("is_home")
    private Integer isHome;
    @TableField("is_system")
    private Integer isSystem;

    /**
     * 开始时间
     */
    private String starttime;

    /**
     * 结束时间
     */
    private String endtime;

    private Integer xinke;
    private Integer fantype;
    private BigDecimal fanmount;
    private Long fanid;

    private Integer fanshu;
    private Integer fxshu;
    private Integer shareshu;

    private Integer isleague;
    private Long leagueid;

//    /**
//     * 生效日期
//     */
//	//@DateTimeFormat(pattern = "yyyy-MM-dd")
//	@TableField("starttime")
//	private Date start;
//    /**
//     * 结束日期
//     */
//	//@DateTimeFormat(pattern = "yyyy-MM-dd")
//	@TableField("endtime")
//	private Date end;


    /**
     * 券价值：如代金券，是多少元；加息券，是加息百分之几；
     */
    private BigDecimal cost;

    /**
     * 券的额度与单位@1:如代金券，是多少元；2:加息券，是加息百分之几；
     */
    private String cunit;

    private String remark;
    /**
     * 使用起始值：满多少条件开始使用
     */
    private BigDecimal usemin;

    /**
     * 使用最高值：最大多少条件开始使用
     */
    private BigDecimal maxvalue;
    /**
     * 适用商品，0代表所有大类别商品能使用  1代表某类型商品 -1个别商品
     */
    private Integer allcategory;
    /**
     * 所有适合大类的类别ID
     */
    private String categories;
    /**
     * 所有适合的商品ids
     */
    private String gids;
    /**
     * 商家id
     */
    private Long mid;

    @TableField(exist = false)
    private Long getuid;

    @TableField(exist = false)
    private String percentage;

    @TableField(exist = false)
    private String typeStr;

//	@TableField(exist = false)
//	private String endtimeStr;

    /**
     * 店铺id
     */
    private Long mpid;
    private Long sid;

    private Long uid;
    private Long modifier;
    private Date createtime;
    private Date modifytime;


    public String getTypeName() {
        if (type == 1) {
            typeName = "代金券";
        } else if (type == 2) {
            typeName = "满减券";
        } else if (type == 3) {
            typeName = "折扣券";
        } else if (type == 4) {
            typeName = "体验金券";
        } else if (type == 5) {
            typeName = "加息券";
        }
        return typeName;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getMpid() {
        return mpid;
    }

    public void setMpid(Long mpid) {
        this.mpid = mpid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getIsRepeat() {
        return isRepeat;
    }

    public void setIsRepeat(Integer isRepeat) {
        this.isRepeat = isRepeat;
    }

    public Integer getRepeatNum() {
        return repeatNum;
    }

    public void setRepeatNum(Integer repeatNum) {
        this.repeatNum = repeatNum;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public BigDecimal getDiscount() {
        return discount;
    }

    public void setDiscount(BigDecimal discount) {
        this.discount = discount;
    }

    public BigDecimal getMaxvalue() {
        return maxvalue;
    }

    public void setMaxvalue(BigDecimal maxvalue) {
        this.maxvalue = maxvalue;
    }

//	public String getStartdate() {
//		startdate = DateUtil.toDateString(startdate,"yyyy-MM-dd");
//		return startdate;
//	}
//
//	public String getEnddate() {
//		enddate = DateUtil.toDateString(enddate,"yyyy-MM-dd");
//		return enddate;
//	}

    public Integer getValidType() {
        return validType;
    }

    public void setValidType(Integer validType) {
        this.validType = validType;
    }

    public Long getCid() {
        return cid;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public Integer getUse() {
        return use;
    }

    public void setUse(Integer use) {
        this.use = use;
    }

    public String getPercentage() {
        if (total != null && total > 0 && use != null) {
            return String.format("%d", use * 100 / total);
        } else return "0";
    }

    public String getTypeStr() {
        String str = "";
        switch (type) {
            case 1:
                return "代金券";
            case 2:
                return "满减券";
            case 3:
                return "折扣券";
//			case 4:
//				return "体验金";
//			case 5:
//				return "加息券";
            case 6:
                return "代金券";
        }
        return "优惠券";
    }

    public void setTypeStr(String typeStr) {
        this.typeStr = typeStr;
    }

//	public String getEndtimeStr() {
//		return DateUtil.toDateString(endtime,"yyyy-MM-dd");
//	}
//
//	public void setEndtimeStr(String endtimeStr) {
//		this.endtimeStr = endtimeStr;
//	}


    public String getStarttime() {
        return starttime;
    }

    public void setStarttime(String starttime) {
        this.starttime = starttime;
    }

    public String getEndtime() {
        return endtime;
    }

    public void setEndtime(String endtime) {
        this.endtime = endtime;
    }

    public BigDecimal getCost() {
        return cost;
    }

    public void setCost(BigDecimal cost) {
        this.cost = cost;
    }

    public String getCunit() {
        return cunit;
    }

    public void setCunit(String cunit) {
        this.cunit = cunit;
    }

    public BigDecimal getUsemin() {
        return usemin;
    }

    public void setUsemin(BigDecimal usemin) {
        this.usemin = usemin;
    }

    public Integer getAllcategory() {
        return allcategory;
    }

    public void setAllcategory(Integer allcategory) {
        this.allcategory = allcategory;
    }

    public String getCategories() {
        return categories;
    }

    public void setCategories(String categories) {
        this.categories = categories;
    }

    public String getGids() {
        return gids;
    }

    public void setGids(String gids) {
        this.gids = gids;
    }

    public Integer getIsForever() {
        return isForever;
    }

    public void setIsForever(Integer isForever) {
        this.isForever = isForever;
    }

    public Long getMid() {
        return mid;
    }

    public void setMid(Long mid) {
        this.mid = mid;
    }

    public Long getGetuid() {
        return getuid == null ? 0 : getuid;
    }

    public void setGetuid(Long getuid) {
        this.getuid = getuid;
    }

    public Integer getIsHome() {
        return isHome;
    }

    public void setIsHome(Integer isHome) {
        this.isHome = isHome;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Date getModifytime() {
        return modifytime;
    }

    public void setModifytime(Date modifytime) {
        this.modifytime = modifytime;
    }

    public Long getModifier() {
        return modifier;
    }

    public void setModifier(Long modifier) {
        this.modifier = modifier;
    }

    public Long getSid() {
        return sid;
    }

    public void setSid(Long sid) {
        this.sid = sid;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public Integer getExpire() {
        return expire;
    }

    public void setExpire(Integer expire) {
        this.expire = expire;
    }

    public Integer getIsSystem() {
        return isSystem;
    }

    public void setIsSystem(Integer isSystem) {
        this.isSystem = isSystem;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public Integer getIsmember() {
        return ismember;
    }

    public void setIsmember(Integer ismember) {
        this.ismember = ismember;
    }

    public Integer getMlevel() {
        return mlevel;
    }

    public void setMlevel(Integer mlevel) {
        this.mlevel = mlevel;
    }

    public Integer getXinke() {
        return xinke;
    }

    public void setXinke(Integer xinke) {
        this.xinke = xinke;
    }

    public Integer getFantype() {
        return fantype;
    }

    public void setFantype(Integer fantype) {
        this.fantype = fantype;
    }

    public BigDecimal getFanmount() {
        return fanmount;
    }

    public void setFanmount(BigDecimal fanmount) {
        this.fanmount = fanmount;
    }

    public Long getFanid() {
        return fanid;
    }

    public void setFanid(Long fanid) {
        this.fanid = fanid;
    }

    public Integer getFxshu() {
        return fxshu;
    }

    public void setFxshu(Integer fxshu) {
        this.fxshu = fxshu;
    }

    public Integer getShareshu() {
        return shareshu;
    }

    public void setShareshu(Integer shareshu) {
        this.shareshu = shareshu;
    }

    public Integer getUsed() {
        return used;
    }

    public void setUsed(Integer used) {
        this.used = used;
    }

    public Integer getFenxiao() {
        return fenxiao;
    }

    public void setFenxiao(Integer fenxiao) {
        this.fenxiao = fenxiao;
    }

    public Integer getZsmode() {
        return zsmode;
    }

    public void setZsmode(Integer zsmode) {
        this.zsmode = zsmode;
    }

    public Integer getFanshu() {
        return fanshu;
    }

    public void setFanshu(Integer fanshu) {
        this.fanshu = fanshu;
    }

    public Integer getIsleague() {
        return isleague;
    }

    public void setIsleague(Integer isleague) {
        this.isleague = isleague;
    }

    public Long getLeagueid() {
        return leagueid;
    }

    public void setLeagueid(Long leagueid) {
        this.leagueid = leagueid;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getXmtype() {
        return xmtype;
    }

    public void setXmtype(String xmtype) {
        this.xmtype = xmtype;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "CouponTpl{" +
                "id=" + id +
                ", name=" + name +
                ", type=" + type +
                ", isRepeat=" + isRepeat +
                ", repeatNum=" + repeatNum +
                ", total=" + total +
                ", state=" + state +
                ", validType=" + validType +
                ", cost=" + cost +
//			", cunit=" + cunit +
                ", usemin=" + usemin +
                ", allcategory=" + allcategory +
                ", categories=" + categories +
                ", gids=" + gids +
                ", mid=" + mid +
                ", uid=" + uid +
                ", createtime=" + createtime +
                ", modifytime=" + modifytime +
                "}";
    }

    public int compareTo(Object o) {
        int result = 0; //返回对比结果 0为相等，负整数为小于，正整数为大于
        if (o instanceof CouponTpl) {
            CouponTpl couponTpl = (CouponTpl)o;
            if (couponTpl.getId() > this.id) {
                return -1;
            } else if (couponTpl.getId() < this.id) {
                return 1;
            }
        }
        return result;
    }
}
